package com.lovo.pis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.pis.dto.BuyCarGoodsBean;
import com.lovo.pis.dto.BuyOrderBean;
import com.lovo.pis.dto.PageBean;
import com.lovo.pis.mapper.BuyCarGoodsMapper;
import com.lovo.pis.mapper.BuyOrderMapper;
import com.lovo.pis.service.IBuyCarGoodsService;
import com.lovo.pis.service.IBuyOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderMapper, BuyOrderBean> implements IBuyOrderService {

    @Autowired
    BuyOrderMapper buyOrderMapper;

    @Override
    public IPage<BuyOrderBean> queryAllBuyCarGoods(PageBean<BuyOrderBean> pageInfo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (pageInfo.getData().getSupplierName() != null && pageInfo.getData().getSupplierName() != "") {
            queryWrapper.like("supplier_name", pageInfo.getData().getSupplierName());
        }
        if (pageInfo.getStartDate() != null && pageInfo.getStartDate() != "") {
            queryWrapper.ge("create_time", pageInfo.getStartDate());
        }
        if (pageInfo.getEndDate() != null && pageInfo.getEndDate() != "") {
            queryWrapper.le("create_time", pageInfo.getEndDate());
        }
        return buyOrderMapper.selectPage(new Page<>(pageInfo.getCurPage(), pageInfo.getPageSize()), queryWrapper);
    }

    @Override
    public BuyOrderBean queryById(int id) {
        return buyOrderMapper.selectByOrderId(id);
    }


}
